﻿using System;
using System.Windows;
using System.Windows.Controls;
using Baosight.ZNH.ZMCommon;
using Baosight.Platform.Core;
using Baosight.Platform.Core.ServiceModel;
using Telerik.Windows.Controls;
using Baosight.ZNH.ZMCommon.ChildWindows;

namespace Baosight.ZNH.ZMCL.UI
{
    /// <summary>
    /// 巡检点下的安全检查项目
    /// </summary>
    /// Title:ZMCL93
    /// Service:ServiceZMCL93
    /// Copyright:Baosight Software LTD.co Copyright (c) 2011
    /// Company:上海宝信软件股份有限公司
    /// Author: 高强
    /// Version: 1.0
    /// History:
    ///       2011-4-2  高强   [创建]
    ///  
    public partial class ZMCL93 : EFViewCmes
    {
        public ZMCL93()
        {
            InitializeComponent();
            base.BeforeAction += OnBeforeAction;
        }

        /// <summary>
        /// 修改前设置属性
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnBeforeAction(object sender, EventArgs e)
        {
            EFViewCmesProperty _view = new EFViewCmesProperty();
            _view.EFGridCheckedRows = this.grid.GetCheckedEIRows();
            _view.ViewType = "tree";
            _view.Args.Add("fdParentId", this.fdParentId.Value.ToString());//巡检点ID
            _view.Args.Add("fdSecuritypathId", this.fdSecuritypathId.Value.ToString());//巡检路线ID
            base.ViewProperty = _view;
        }

        /// <summary>
        /// 点击新增巡检点按钮，弹出新增页面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void OnInsertButtonClick(object sender, RoutedEventArgs e)
        {
            EIInfo eiInfo = new EIInfo();
            Button but = sender as Button;
            but.IsEnabled = false;
            TempButton = but;
            eiInfo.Set("fdItemInfo", "");
            eiInfo.AddBlock(EIConstants.ResultBlock);
            HttpServiceAgent agent = new HttpServiceAgent();
            eiInfo.Attributes.Add(EIConstants.ServiceNameKey, "ZMCL93");
            eiInfo.Attributes.Add(EIConstants.MethodNameKey, "queryAllItem");
            agent.CallService(eiInfo, OnDoSelectCompleted);
        }

        /// <summary>
        /// 选择检查项目的回调函数
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnDoSelectCompleted(object sender, DoWorkCompletedEventArgs e)
        {
            if (e.EIInfo.Status == -1)
            {
                base.OpenEFWindowAlert(e.EIInfo.DetailMsg, true);
                return;
            }

            if (e.EIInfo.GetBlock(EIConstants.ResultBlock).GetRowCount() == 0)
            {
                base.OpenEFWindowAlert("没有检查项目供选择", true);
                return;
            }
            SelectItem selectItem = new SelectItem();
            CmesWindows _popup = new CmesWindows();//构造一个弹出页面
            _popup.Header = "选择检查项目";
            _popup.ResizeMode = ResizeMode.NoResize; ;//设置不能新增窗口大小
            _popup.WindowStartupLocation = Telerik.Windows.Controls.WindowStartupLocation.CenterScreen;
            selectItem.EIDataContext = new Platform.Core.UI.EIDataContext();
            selectItem.EIDataContext.Update(e.EIInfo);
            _popup.Content = selectItem;//让新增页面在弹出窗口显示
            _popup.Closed += new EventHandler<WindowClosedEventArgs>(Window_Closed);
            _popup.ShowDialog();
        }

        /// <summary>
        /// 弹出窗口关闭时执行的方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_Closed(object sender, WindowClosedEventArgs e)
        {
            if (e.DialogResult == true)
            {
                this.grid.Refresh();//刷新Grid区域
            }

            //按钮生效
            base.TempButtonOpen(true);
        }

        /// <summary>
        /// 点击设为非重点
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnModifyImportantIsNoButtonClick(object sender, RoutedEventArgs e)
        {
            base.OnModifyButtonClick("modifyImportantIsNo", "取消重点", sender, e);
        }

        /// <summary>
        /// 点击设为重点
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnModifyImportantIsYesButtonClick(object sender, RoutedEventArgs e)
        {
            base.OnModifyButtonClick("modifyImportantIsYes", "标记重点", sender, e);
        }

        /// <summary>
        /// 点击取消检查项按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void OnDeleteButtonClick(object sender, RoutedEventArgs e)
        {
            base.OnDeleteButtonClick("取消", sender, e);
        }
    }
}
